// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import path = require('path');
import * as vscode from 'vscode';
import htmlCode from "./html/index.html";
// console.log(htmlCode);
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

    // Use the console to output diagnostic information (console.log) and errors (console.error)
    // This line of code will only be executed once when your extension is activated
    console.log('Congratulations, your extension "vieweditor" is now active!');

    // The command has been defined in the package.json file
    // Now provide the implementation of the command with registerCommand
    // The commandId parameter must match the command field in package.json
    // let disposable = vscode.commands.registerCommand('vieweditor.helloWorld', () => {
    //     // The code you place here will be executed every time your command is executed
    //     // Display a message box to the user
    //     vscode.window.showInformationMessage(context.asAbsolutePath("/src/views"));
    // });
    context.subscriptions.push(
        vscode.commands.registerCommand('vieweditor.helloWorld', () => {

            const panel = vscode.window.createWebviewPanel(
                'vieweditor',
                '视图信息编辑器',
                vscode.ViewColumn.One,
                { enableScripts: true }
            );
            panel.iconPath = {
                light: vscode.Uri.parse("https://ss0.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2288154050,1961487294&fm=26&gp=0.jpg"),
                dark: vscode.Uri.parse("https://ss0.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2288154050,1961487294&fm=26&gp=0.jpg")
            };

            const onDiskPath = vscode.Uri.file(
                path.join(context.extensionPath, 'media', 'cat.gif')
            );
            panel.webview.html = htmlCode;
            panel.webview.onDidReceiveMessage(
                (message: any) => {
                    console.log(message);
                    switch (message.command) {
                        case 'alert':
                            console.log("接到消息：alert");
                            vscode.window.showInformationMessage(message.text);
                            return;
                    }
                },
                "wang",
                context.subscriptions
            );
        })
    );


    // context.subscriptions.push(disposable);
}
// this method is called when your extension is deactivated
export function deactivate() { }
